﻿using System;
using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabrication.Tests
{
    [TestFixture]
    public class char_rules
    {
        [Test]
        public void should_generate_random_initial()
        {
            var builtItem = new FabricationScope().Setup<InitialsConventionClass>()
                            .For(x => x.Initial).GenerateInitial()
                            .Generate();

            Assert.That("ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(builtItem.Initial.ToString()));
        }

        [Test]
        public void should_generate_random_surname()
        {
            var builtItem = new FabricationScope().Setup<SinglePropertyClass<string>>()
                            .For(x => x.Value).GenerateLastName()
                            .Generate();

            Assert.That(builtItem.Value, Is.Not.Empty);
        }

        [Test]
        public void should_use_default_if_convention_property_name_has_mismatched_type()
        {
            var builtItem = new FabricationScope().Generate<NumericNameClass>();

            Assert.That(builtItem.FirstName, Is.EqualTo(1));
        }

        [Test]
        public void should_generate_random_initial_for_conventional_initial_properties()
        {
            var builtItem = new FabricationScope().Generate<InitialsConventionClass>();

            Assert.That(Char.IsUpper(builtItem.Initial));
        }

        [Test]
        public void should_use_defined_rule_over_convention()
        {
            var builtItem = new FabricationScope().Setup<NamesConventionClass>()
                            .For(x => x.FirstName).Use("Custom")
                            .Generate();

            Assert.That(builtItem.FirstName, Is.EqualTo("Custom"));
        }
    }
}
